package v1

import (
	"gin-ebook/Models"
	"gin-ebook/pkg/e"
	"gin-ebook/pkg/util"
	"github.com/gin-gonic/gin"
)

// @Summary 获取标签
// @Produce  json
// @accept json
// @Tags Tags
// @Param name query string false "Name"
// @Success 200 {string} string "{"code":200,"data":{},"msg":"ok"}"
// @Router /tags [get]
func GetTags(c *gin.Context, maps map[string]interface{}) (lists []models.Category, total int64) {
	page, pageSize := util.GetPage(c)
	lists = models.GetTags(page, pageSize, maps)
	total = models.GetTagTotal(maps)
	return
}

// @Summary 增加标签
// @Produce  json
// @Tags Tags
// @Param name query string true "Name"  maxlength(100)
// @Param state query string false "State(0或者1)"
// @Param created_by query string true "createdBy" maxlength(100)
// @Success 200 {string} string "{"code":200,"data":{},"msg":"ok"}"
// @Router /tags [post]
func AddTag(c *gin.Context, name string, state int, createdBy string) (code int) {
	//if !models.ExistTagByName(name) {
	//	code = e.SUCCESS
	//	models.AddTag(name, state, createdBy)
	//	AddDynamic(name, "增加标签", createdBy)
	//
	//} else {
	//	code = e.ERROR_EXIST_TAG
	//}
	return code
}

// @Summary 修改标签
// @Produce  json
// @Tags Tags
// @Param id path int true "需要修改的标签id"
// @Param name query string true "修改内容（Name）"
// @Param state query int false "修改内容（State）"
// @Param modified_by query string true "修改内容（ModifiedBy）"
// @Success 200 {string} string "{"code":200,"data":{},"msg":"ok"}"
// @Router /tags/{id} [put]
func EditTag(id int, name string, modifiedBy string, state int) (code int) {
	code = e.SUCCESS

	// 存在标签则执行修改标签函数
	//if models.ExistTagByID(id) {
	//	data := make(map[string]interface{})
	//	data["modified_by"] = modifiedBy
	//	if name != "" {
	//		data["name"] = name
	//	}
	//	if state != -1 {
	//		data["state"] = state
	//	}
	//
	//	models.EditTag(id, data)
	//	AddDynamic(name, "编辑标签", modifiedBy)
	//
	//} else {
	//	code = e.ERROR_NOT_EXIST_TAG
	//}
	return
}

// @Summary 删除标签
// @Produce  json
// @Tags Tags
// @Param id path int true "标签id"
// @Success 200 {string} string "{"code":200,"data":{},"msg":"ok"}"
// @Router /tags/{id} [delete]
func DeleteTag(id int) (code int) {
	//code = e.SUCCESS
	//if models.ExistTagByID(id) {
	//	models.DeleteTag(id)
	//	AddDynamic(string(id), "删除标签", "布丁")
	//
	//} else {
	//	code = e.ERROR_NOT_EXIST_TAG
	//}
	return
}
